{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "40edaa2f",
   "metadata": {},
   "source": [
    "* 日期：2022.10.19\n",
    "* 记录人：liyuanyuan"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d413dc47",
   "metadata": {},
   "source": [
    "# 本周学习目标\n",
    "\n",
    "> 1. 列表的方法\n",
    "\n",
    "> 2. while循环"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0730b717",
   "metadata": {},
   "source": [
    "## 列表的方法\n",
    "> 1. 使用.tab键查看列表的方法\n",
    "> 2. 使用help（查看方法的使用规则）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4743b559",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'marry', 'jan']"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"jack\",\"alex\",\"marry\",\"jan\"]\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "220ff5dd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'marry', 'jan', 'lihua']"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.append(\"lihua\")\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3a47a839",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ed38a7b9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function insert:\n",
      "\n",
      "insert(index, object, /) method of builtins.list instance\n",
      "    Insert object before index.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.insert)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "de01a04d",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'zhichao', 'marry', 'jan', 'lihua']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.insert(2,\"zhichao\")\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79fc0e72",
   "metadata": {},
   "source": [
    "### 2.列表的删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c2aaed7f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ca6af4f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.remove(\"zhichao\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "8ee969f6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'marry', 'jan', 'lihua']"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7c3bca33",
   "metadata": {},
   "source": [
    "* 正确的删除方法的流程\n",
    "> 1. 查询value是否存在列表当中\n",
    "> 2. 对存在的value进行删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "992b717e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"wang\" in names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "7a7a124e",
   "metadata": {},
   "outputs": [],
   "source": [
    "if \"wang\" in names:\n",
    "    names.remove(\"wang\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "126fa782",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践：删除系统：\n",
    "## 1.如果输入的值存在，删除； 2.如果输入的结果不存在，提示用户查询无结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "94c9d10e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'marry', 'jan', 'lihua']"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "60027862",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入要删除的内容：00\n",
      "您输入的结果不存在，删除无效\n",
      "['jack', 'jan', 'lihua']\n"
     ]
    }
   ],
   "source": [
    "user_input_name = input(\"请输入要删除的内容：\")\n",
    "if user_input_name in names:\n",
    "    names.remove(user_input_name)\n",
    "    print(\"删除成功！\")\n",
    "else:\n",
    "    print(\"您输入的结果不存在，删除无效\")\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1216e2d5",
   "metadata": {},
   "source": [
    "### 列表的删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "181fae5f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'marry', 'jan', 'lihua']"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 重新建立names列表数据\n",
    "names = [\"jack\",\"alex\",\"marry\",\"jan\",\"lihua\"]\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "bbb85ad2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(index=-1, /) method of builtins.list instance\n",
      "    Remove and return item at index (default last).\n",
      "    \n",
      "    Raises IndexError if list is empty or index is out of range.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.pop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "d884a4da",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'lihua'"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.pop()   # 直接使用pop（），删除最后一位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "86ab2645",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'marry', 'jan']"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "0601dedf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'jan']"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.pop(2)\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "96ec3231",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "8032bd14",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输入删除的索引值：2\n"
     ]
    }
   ],
   "source": [
    "pop_index = int(input(\"输入删除的索引值：\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "65096466",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "删除成功！\n"
     ]
    }
   ],
   "source": [
    "if pop_index<len(names):\n",
    "    names.pop(pop_index)\n",
    "    print(\"删除成功！\")\n",
    "else:\n",
    "    print(\"您输入的值不存在index的范围内\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "e7599a34",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex']"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "395004fb",
   "metadata": {},
   "source": [
    "### 3.列表的修改"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "a3a019ec",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['zhichao', 'alex']"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[0] = \"zhichao\"\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46fe31e9",
   "metadata": {},
   "source": [
    "### 4.列表的其他方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "26ed87a9",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"jack\",\"alex\",\"marry\",\"jan\",\"lihua\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "1c3df2e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.clear()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "4944a7fb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "f7942896",
   "metadata": {},
   "outputs": [],
   "source": [
    "names_class1 = [\"jack\",\"alex\",\"marry\",\"jan\",\"lihua\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "d0e3f04b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function extend:\n",
      "\n",
      "extend(iterable, /) method of builtins.list instance\n",
      "    Extend list by appending elements from the iterable.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.extend)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "f1f144be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['李晓峰', '王丽', '刘明']"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names_class2 = [\"李晓峰\",\"王丽\",\"刘明\"]\n",
    "names_class2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "ef771e8c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'marry', 'jan', 'lihua', '李晓峰', '王丽', '刘明']"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names_class1.extend(names_class2)  #注意：使用列表的方法的列表进行扩展\n",
    "names_class1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "69280f49",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'marry', 'jan', 'lihua', '李晓峰', '王丽', '刘明']"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names_class1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "feed570b",
   "metadata": {},
   "source": [
    "---\n",
    "* sort()排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "1c5e0383",
   "metadata": {},
   "outputs": [],
   "source": [
    "立定跳远_男生 = [230,250,245,255,260,270]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "d6c84baa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function sort:\n",
      "\n",
      "sort(*, key=None, reverse=False) method of builtins.list instance\n",
      "    Sort the list in ascending order and return None.\n",
      "    \n",
      "    The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n",
      "    order of two equal elements is maintained).\n",
      "    \n",
      "    If a key function is given, apply it once to each list item and sort them,\n",
      "    ascending or descending, according to their function values.\n",
      "    \n",
      "    The reverse flag can be set to sort in descending order.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(立定跳远_男生.sort)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "40adbbfb",
   "metadata": {},
   "outputs": [],
   "source": [
    "立定跳远_男生.sort()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "c657bdf5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[230, 245, 250, 255, 260, 270]"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "立定跳远_男生"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "fed1c6ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "立定跳远_男生.sort(reverse=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "348a1369",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[270, 260, 255, 250, 245, 230]"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "立定跳远_男生"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "046413b4",
   "metadata": {},
   "source": [
    "## 2.while循环\n",
    "\n",
    "* while True 是循环概念中非常重要的一种方式，它可以实现for循环指定的次数，也可以在特定条件下停止"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "9ccdbb26",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是风儿我是沙，缠缠绵绵到天涯... 0\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 1\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 2\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 3\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 4\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 5\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 6\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 7\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 8\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 9\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 10\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 11\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 12\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 13\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 14\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 15\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 16\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 17\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 18\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 19\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 20\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 21\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 22\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 23\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 24\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 25\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 26\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 27\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 28\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 29\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 30\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 31\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 32\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 33\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 34\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 35\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 36\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 37\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 38\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 39\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 40\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 41\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 42\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 43\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 44\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 45\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 46\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 47\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 48\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 49\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 50\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 51\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 52\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 53\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 54\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 55\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 56\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 57\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 58\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 59\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 60\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 61\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 62\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 63\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 64\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 65\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 66\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 67\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 68\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 69\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 70\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 71\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 72\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 73\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 74\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 75\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 76\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 77\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 78\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 79\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 80\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 81\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 82\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 83\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 84\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 85\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 86\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 87\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 88\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 89\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 90\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 91\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 92\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 93\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 94\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 95\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 96\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 97\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 98\n",
      "你是风儿我是沙，缠缠绵绵到天涯... 99\n"
     ]
    }
   ],
   "source": [
    "# 它可以实现for循环的指定次数\n",
    "count = 0\n",
    "while True:\n",
    "    print(\"你是风儿我是沙，缠缠绵绵到天涯...\",count)\n",
    "    count = count+1\n",
    "    if count ==100:\n",
    "        break\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "700fa010",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hide_card88\n",
      "猜一猜（0-100)：66\n",
      "往大的猜！\n",
      "猜一猜（0-100)：77\n",
      "往大的猜！\n",
      "猜一猜（0-100)：88\n",
      "你超棒！！！\n"
     ]
    }
   ],
   "source": [
    "## 小游戏：猜数字，5次\n",
    "# 1.hide_card:0-100,大了，小了\n",
    "# 2.guess_digit:50\n",
    "count = 0\n",
    "hide_card = int(input(\"hide_card\"))\n",
    "while True:\n",
    "    guess_digit = int(input(\"猜一猜（0-100)：\"))\n",
    "# 对比\n",
    "    if hide_card == guess_digit:\n",
    "        print(\"你超棒！！！\")\n",
    "        break\n",
    "    elif guess_digit>hide_card:\n",
    "        print(\"往小猜！加油！\")\n",
    "    else:\n",
    "        print(\"往大的猜！\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b85c0c63",
   "metadata": {},
   "source": [
    "# 课后练习：\n",
    "> 1. 列表的切片和方法的使用   <font color=\"blue\">注：列表方法会改变一个列表的状态，而使用中括号记法和切片通常不会改变列表状态</font>\n",
    ">> 1. 课本p67练习\n",
    ">> 2. 课本p81练习\n",
    "> 2. p89:列表，我们已经知道什么（列表总结）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "91d75222",
   "metadata": {},
   "source": [
    "## 课本P67练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "93f83051",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "don't panic!\n",
      "['d', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    }
   ],
   "source": [
    "phrase = \"don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "1c8855ca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['d', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c']\n",
      "['d', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i']\n",
      "['d', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n']\n",
      "['d', 'o', 'n', \"'\", 't', ' ', 'p', 'a']\n"
     ]
    }
   ],
   "source": [
    "for i in range(4):\n",
    "    plist.pop()\n",
    "    print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "ec6828c3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['o', 'n', \"'\", 't', ' ', 'p', 'a']\n"
     ]
    }
   ],
   "source": [
    "plist.pop(0)\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "51510589",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['o', 'n', \"'\", 't', ' ', 'a', 'p']\n"
     ]
    }
   ],
   "source": [
    "plist.extend([plist.pop(),plist.pop()])\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "6ae62a96",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['o', 'n', 't', ' ', 'a', 'p']\n"
     ]
    }
   ],
   "source": [
    "plist.remove(\"'\")\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "b39e5f6f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['o', 'n', ' ', 't', 'a', 'p']\n"
     ]
    }
   ],
   "source": [
    "plist.insert(2,plist.pop(3))\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "f7c59f51",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "on tap\n"
     ]
    }
   ],
   "source": [
    "new_phrase = ''.join(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cb1efe14",
   "metadata": {},
   "source": [
    "## 课本P81页练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "c068644e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['d', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    }
   ],
   "source": [
    "phrase = \"don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "9fdf5494",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "on tap\n"
     ]
    }
   ],
   "source": [
    "new_phrase = ''.join(plist[1:3])\n",
    "new_phrase = new_phrase+''.join([plist[5],plist[4],plist[7],plist[6]])\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a6a38a9f",
   "metadata": {},
   "source": [
    "## p86"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "4c0f991b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['m', 'a', 'r', 'v', 'i', 'n']\n",
      "m\n",
      "a\n",
      "r\n",
      "v\n",
      "i\n",
      "n\n"
     ]
    }
   ],
   "source": [
    "l = \"marvin\"\n",
    "plist = list(l)\n",
    "print(plist)\n",
    "for i in plist:\n",
    "        print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "a82658ef",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['m', 'a', 'r', 'v', 'i', 'n']\n",
      "\t m\n",
      "\t a\n",
      "\t r\n",
      "\t v\n",
      "\t i\n",
      "\t n\n"
     ]
    }
   ],
   "source": [
    "l = \"marvin\"\n",
    "plist = list(l)\n",
    "print(plist)\n",
    "for i in plist:\n",
    "    print('\\t',i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "34c1295b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t m\n",
      "\t a\n",
      "\t r\n",
      "\t v\n",
      "\t i\n",
      "\t n\n",
      "\n",
      "\t\t a\n",
      "\t\t n\n",
      "\t\t d\n",
      "\t\t r\n",
      "\t\t o\n",
      "\t\t i\n",
      "\t\t d\n",
      "\n",
      "\t\t\t p\n",
      "\t\t\t a\n",
      "\t\t\t r\n",
      "\t\t\t a\n",
      "\t\t\t n\n",
      "\t\t\t o\n",
      "\t\t\t i\n",
      "\t\t\t d\n"
     ]
    }
   ],
   "source": [
    "l = \"marvin, the paranoid android\"\n",
    "plist = list(l)\n",
    "for i in plist[:6]:\n",
    "    print('\\t',i)\n",
    "print()\n",
    "for i in plist[-7:]:\n",
    "    print('\\t'*2,i)\n",
    "print()\n",
    "for i in plist[12:20]:\n",
    "    print('\\t'*3,i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3931908c",
   "metadata": {},
   "source": [
    "## 列表总结"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9517f820",
   "metadata": {},
   "source": [
    "|一些列表新知|描述|\n",
    "|:---|:---|\n",
    "|while循环|while True 是循环概念中非常重要的一种方式，它可以实现for循环指定的次数，也可以在特定条件下通过break停止|\n",
    "|列表切片具有非破坏性|列表方法会改变一个列表的状态，而使用中括号记法和切片通常不会改变列表状态|\n",
    "|方法可灵活搭配使用|如：plist.extend([plist.pop(),plist.pop()])先弹出，再调用对象|\n",
    "|字符串转列表|使用list(name)|\n",
    "|列表转字符串|使用''.join(name)|\n",
    "|'\\t'|制表符，可用python的乘法操作符，如'\\t'*2|\n",
    "|print()|输出空白行|\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
